//SPDX-FileCopyrightText: Copyright 2022-2024 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package impl

import (
	"context"

	"atomgit.com/openlinksaas-org/netutil/gen_code"
)

type IcmpApiImpl struct{}

func (s *IcmpApiImpl) IcmpPingPost(ctx context.Context, req gen_code.IcmpPingPostRequest) (gen_code.ImplResponse, error) {
	if req.Token != token {
		return gen_code.ImplResponse{
			Code: 500,
			Body: gen_code.ErrInfo{
				ErrMsg: "wrong token",
			},
		}, nil
	}

	rtt, err := Ping(req.Addr, req.PkgSize)
	success := true
	if err != nil {
		success = false
	}
	return gen_code.ImplResponse{
		Code: 200,
		Body: gen_code.IcmpPingPost200Response{
			Success: success,
			Rtt:     int32(rtt),
		},
	}, nil
}
